package com.sfj.system.controller;

import com.kaka.starter.control.dto.ResultBean;
import com.sfj.system.dto.role.RoleInfoDTO;
import com.sfj.system.dto.role.RoleInfoUpdDTO;
import com.sfj.system.dto.role.RoleQueryDTO;
import com.sfj.system.service.role.RoleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author kaka
 * @Date 2025/06/29
 */
@RestController
@RequestMapping("role")
@Api(tags = "角色管理")
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;

    @PostMapping("/queryById")
    @ApiOperation(value = "根据ID查询角色信息", notes = "根据角色ID返回角色详情")
    public ResultBean queryRoleById(@RequestBody Integer roleId) {
        return ResultBean.succeed(roleInfoService.getRoleWithFuncIds(roleId));
    }

    @PostMapping("/query")
    @ApiOperation(value = "查询所有角色", notes = "返回全部角色列表")
    public ResultBean queryRoleList(@RequestBody RoleQueryDTO roleQueryDTO) {
        return ResultBean.succeed(roleInfoService.queryRoleList(roleQueryDTO));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询所有角色(不分页)", notes = "查询所有角色(不分页)")
    public ResultBean list() {
        return ResultBean.succeed(roleInfoService.queryRoleList());
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增角色", notes = "包含角色基本信息和菜单权限")
    public ResultBean addRole(@RequestBody @Validated RoleInfoDTO dto) {
        roleInfoService.createRole(dto);
        return ResultBean.succeed("创建成功");
    }

    @PostMapping("/upd")
    @ApiOperation(value = "更新角色", notes = "根据ID更新角色信息和菜单权限")
    public ResultBean updateRole(@RequestBody @Validated RoleInfoUpdDTO dto) {
        roleInfoService.updateRole( dto);
        return ResultBean.succeed("更新成功");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除角色", notes = "根据ID删除角色及其菜单映射")
    public ResultBean deleteRole(@RequestBody Integer roleId) {
        roleInfoService.deleteRole(roleId);
        return ResultBean.succeed("删除成功");
    }
}


